﻿using System;
using System.Collections.Generic;
using System.Linq;
using Helpers;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.ComponentInterfaces;
using TaleWorlds.CampaignSystem.Encounters;
using TaleWorlds.CampaignSystem.Map;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Roster;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.CampaignSystem.Siege;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.LinQuick;
using TaleWorlds.Localization;
using TaleWorlds.ObjectSystem;
using TaleWorlds.SaveSystem;
using TaleWorlds.SaveSystem.Load;

namespace TaleWorlds.CampaignSystem.MapEvents
{
	// Token: 0x020002B5 RID: 693
	public sealed class MapEvent : MBObjectBase, IMapEntity
	{
		// Token: 0x06002843 RID: 10307 RVA: 0x000AB91C File Offset: 0x000A9B1C
		internal static void AutoGeneratedStaticCollectObjectsMapEvent(object o, List<object> collectedObjects)
		{
			((MapEvent)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
		}

		// Token: 0x06002844 RID: 10308 RVA: 0x000AB92C File Offset: 0x000A9B2C
		protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
		{
			base.AutoGeneratedInstanceCollectObjects(collectedObjects);
			collectedObjects.Add(this.StrengthOfSide);
			collectedObjects.Add(this._sides);
			CampaignTime.AutoGeneratedStaticCollectObjectsCampaignTime(this._nextSimulationTime, collectedObjects);
			CampaignTime.AutoGeneratedStaticCollectObjectsCampaignTime(this._mapEventStartTime, collectedObjects);
			collectedObjects.Add(this.Component);
			collectedObjects.Add(this.MapEventSettlement);
		}

		// Token: 0x06002845 RID: 10309 RVA: 0x000AB992 File Offset: 0x000A9B92
		internal static object AutoGeneratedGetMemberValueComponent(object o)
		{
			return ((MapEvent)o).Component;
		}

		// Token: 0x06002846 RID: 10310 RVA: 0x000AB99F File Offset: 0x000A9B9F
		internal static object AutoGeneratedGetMemberValueMapEventSettlement(object o)
		{
			return ((MapEvent)o).MapEventSettlement;
		}

		// Token: 0x06002847 RID: 10311 RVA: 0x000AB9AC File Offset: 0x000A9BAC
		internal static object AutoGeneratedGetMemberValuePosition(object o)
		{
			return ((MapEvent)o).Position;
		}

		// Token: 0x06002848 RID: 10312 RVA: 0x000AB9BE File Offset: 0x000A9BBE
		internal static object AutoGeneratedGetMemberValueIsInvulnerable(object o)
		{
			return ((MapEvent)o).IsInvulnerable;
		}

		// Token: 0x06002849 RID: 10313 RVA: 0x000AB9D0 File Offset: 0x000A9BD0
		internal static object AutoGeneratedGetMemberValueIsPlayerSimulation(object o)
		{
			return ((MapEvent)o).IsPlayerSimulation;
		}

		// Token: 0x0600284A RID: 10314 RVA: 0x000AB9E2 File Offset: 0x000A9BE2
		internal static object AutoGeneratedGetMemberValueStrengthOfSide(object o)
		{
			return ((MapEvent)o).StrengthOfSide;
		}

		// Token: 0x0600284B RID: 10315 RVA: 0x000AB9EF File Offset: 0x000A9BEF
		internal static object AutoGeneratedGetMemberValue_state(object o)
		{
			return ((MapEvent)o)._state;
		}

		// Token: 0x0600284C RID: 10316 RVA: 0x000ABA01 File Offset: 0x000A9C01
		internal static object AutoGeneratedGetMemberValue_sides(object o)
		{
			return ((MapEvent)o)._sides;
		}

		// Token: 0x0600284D RID: 10317 RVA: 0x000ABA0E File Offset: 0x000A9C0E
		internal static object AutoGeneratedGetMemberValue_mapEventUpdateCount(object o)
		{
			return ((MapEvent)o)._mapEventUpdateCount;
		}

		// Token: 0x0600284E RID: 10318 RVA: 0x000ABA20 File Offset: 0x000A9C20
		internal static object AutoGeneratedGetMemberValue_nextSimulationTime(object o)
		{
			return ((MapEvent)o)._nextSimulationTime;
		}

		// Token: 0x0600284F RID: 10319 RVA: 0x000ABA32 File Offset: 0x000A9C32
		internal static object AutoGeneratedGetMemberValue_mapEventStartTime(object o)
		{
			return ((MapEvent)o)._mapEventStartTime;
		}

		// Token: 0x06002850 RID: 10320 RVA: 0x000ABA44 File Offset: 0x000A9C44
		internal static object AutoGeneratedGetMemberValue_mapEventType(object o)
		{
			return ((MapEvent)o)._mapEventType;
		}

		// Token: 0x06002851 RID: 10321 RVA: 0x000ABA56 File Offset: 0x000A9C56
		internal static object AutoGeneratedGetMemberValue_isVisible(object o)
		{
			return ((MapEvent)o)._isVisible;
		}

		// Token: 0x06002852 RID: 10322 RVA: 0x000ABA68 File Offset: 0x000A9C68
		internal static object AutoGeneratedGetMemberValueFirstUpdateIsDone(object o)
		{
			return ((MapEvent)o).FirstUpdateIsDone;
		}

		// Token: 0x06002853 RID: 10323 RVA: 0x000ABA7A File Offset: 0x000A9C7A
		internal static object AutoGeneratedGetMemberValue_battleState(object o)
		{
			return ((MapEvent)o)._battleState;
		}

		// Token: 0x17000A21 RID: 2593
		// (get) Token: 0x06002854 RID: 10324 RVA: 0x000ABA8C File Offset: 0x000A9C8C
		public static MapEvent PlayerMapEvent
		{
			get
			{
				MobileParty mainParty = MobileParty.MainParty;
				if (mainParty == null)
				{
					return null;
				}
				return mainParty.MapEvent;
			}
		}

		// Token: 0x17000A22 RID: 2594
		// (get) Token: 0x06002855 RID: 10325 RVA: 0x000ABA9E File Offset: 0x000A9C9E
		public BattleSideEnum PlayerSide
		{
			get
			{
				return PartyBase.MainParty.Side;
			}
		}

		// Token: 0x17000A23 RID: 2595
		// (get) Token: 0x06002856 RID: 10326 RVA: 0x000ABAAA File Offset: 0x000A9CAA
		// (set) Token: 0x06002857 RID: 10327 RVA: 0x000ABAB2 File Offset: 0x000A9CB2
		internal IBattleObserver BattleObserver { get; set; }

		// Token: 0x17000A24 RID: 2596
		// (get) Token: 0x06002858 RID: 10328 RVA: 0x000ABABB File Offset: 0x000A9CBB
		// (set) Token: 0x06002859 RID: 10329 RVA: 0x000ABAC3 File Offset: 0x000A9CC3
		[SaveableProperty(105)]
		public MapEventComponent Component { get; private set; }

		// Token: 0x17000A25 RID: 2597
		// (get) Token: 0x0600285A RID: 10330 RVA: 0x000ABACC File Offset: 0x000A9CCC
		// (set) Token: 0x0600285B RID: 10331 RVA: 0x000ABAD4 File Offset: 0x000A9CD4
		public MapEventState State
		{
			get
			{
				return this._state;
			}
			private set
			{
				if (this._state != value)
				{
					if (this.IsPlayerMapEvent)
					{
						Debug.Print("Player MapEvent State: " + value.ToString(), 0, Debug.DebugColor.White, 17592186044416UL);
					}
					this._state = value;
				}
			}
		}

		// Token: 0x0600285C RID: 10332 RVA: 0x000ABB21 File Offset: 0x000A9D21
		public void BeginWait()
		{
			this.State = MapEventState.Wait;
		}

		// Token: 0x17000A26 RID: 2598
		// (get) Token: 0x0600285D RID: 10333 RVA: 0x000ABB2A File Offset: 0x000A9D2A
		public MapEventSide AttackerSide
		{
			get
			{
				return this._sides[1];
			}
		}

		// Token: 0x17000A27 RID: 2599
		// (get) Token: 0x0600285E RID: 10334 RVA: 0x000ABB34 File Offset: 0x000A9D34
		public MapEventSide DefenderSide
		{
			get
			{
				return this._sides[0];
			}
		}

		// Token: 0x0600285F RID: 10335 RVA: 0x000ABB3E File Offset: 0x000A9D3E
		public MapEventSide GetMapEventSide(BattleSideEnum side)
		{
			return this._sides[(int)side];
		}

		// Token: 0x06002860 RID: 10336 RVA: 0x000ABB48 File Offset: 0x000A9D48
		internal TroopRoster GetMemberRosterReceivingLootShare(PartyBase party)
		{
			return this._sides[(int)party.Side].MemberRosterForPlayerLootShare(party);
		}

		// Token: 0x06002861 RID: 10337 RVA: 0x000ABB5D File Offset: 0x000A9D5D
		internal TroopRoster GetPrisonerRosterReceivingLootShare(PartyBase party)
		{
			return this._sides[(int)party.Side].PrisonerRosterForPlayerLootShare(party);
		}

		// Token: 0x06002862 RID: 10338 RVA: 0x000ABB72 File Offset: 0x000A9D72
		internal ItemRoster GetItemRosterReceivingLootShare(PartyBase party)
		{
			return this._sides[(int)party.Side].ItemRosterForPlayerLootShare(party);
		}

		// Token: 0x06002863 RID: 10339 RVA: 0x000ABB87 File Offset: 0x000A9D87
		public MBReadOnlyList<MapEventParty> PartiesOnSide(BattleSideEnum side)
		{
			return this._sides[(int)side].Parties;
		}

		// Token: 0x17000A28 RID: 2600
		// (get) Token: 0x06002864 RID: 10340 RVA: 0x000ABB96 File Offset: 0x000A9D96
		public IEnumerable<PartyBase> InvolvedParties
		{
			get
			{
				foreach (MapEventSide mapEventSide in this._sides)
				{
					foreach (MapEventParty mapEventParty in mapEventSide.Parties)
					{
						yield return mapEventParty.Party;
					}
					List<MapEventParty>.Enumerator enumerator = default(List<MapEventParty>.Enumerator);
				}
				MapEventSide[] array = null;
				yield break;
				yield break;
			}
		}

		// Token: 0x17000A29 RID: 2601
		// (get) Token: 0x06002865 RID: 10341 RVA: 0x000ABBA6 File Offset: 0x000A9DA6
		// (set) Token: 0x06002866 RID: 10342 RVA: 0x000ABBAE File Offset: 0x000A9DAE
		[SaveableProperty(103)]
		public Settlement MapEventSettlement { get; private set; }

		// Token: 0x17000A2A RID: 2602
		// (get) Token: 0x06002867 RID: 10343 RVA: 0x000ABBB7 File Offset: 0x000A9DB7
		// (set) Token: 0x06002868 RID: 10344 RVA: 0x000ABBBF File Offset: 0x000A9DBF
		internal bool AttackersRanAway { get; private set; }

		// Token: 0x06002869 RID: 10345 RVA: 0x000ABBC8 File Offset: 0x000A9DC8
		public void GetBattleRewards(PartyBase party, out float renownChange, out float influenceChange, out float moraleChange, out float goldChange, out float playerEarnedLootPercentage)
		{
			renownChange = 0f;
			influenceChange = 0f;
			moraleChange = 0f;
			goldChange = 0f;
			playerEarnedLootPercentage = 0f;
			MapEventSide[] sides = this._sides;
			for (int i = 0; i < sides.Length; i++)
			{
				foreach (MapEventParty mapEventParty in sides[i].Parties)
				{
					if (party == mapEventParty.Party)
					{
						renownChange = mapEventParty.GainedRenown;
						influenceChange = mapEventParty.GainedInfluence;
						moraleChange = mapEventParty.MoraleChange;
						goldChange = (float)(mapEventParty.PlunderedGold - mapEventParty.GoldLost);
						float num = (float)this.GetMapEventSide(mapEventParty.Party.Side).CalculateTotalContribution();
						playerEarnedLootPercentage = (float)((int)(100f * ((float)mapEventParty.ContributionToBattle / num)));
					}
				}
			}
		}

		// Token: 0x17000A2B RID: 2603
		// (get) Token: 0x0600286A RID: 10346 RVA: 0x000ABCB8 File Offset: 0x000A9EB8
		// (set) Token: 0x0600286B RID: 10347 RVA: 0x000ABCC0 File Offset: 0x000A9EC0
		[SaveableProperty(111)]
		public Vec2 Position { get; private set; }

		// Token: 0x17000A2C RID: 2604
		// (get) Token: 0x0600286C RID: 10348 RVA: 0x000ABCC9 File Offset: 0x000A9EC9
		public MapEvent.BattleTypes EventType
		{
			get
			{
				return this._mapEventType;
			}
		}

		// Token: 0x17000A2D RID: 2605
		// (get) Token: 0x0600286D RID: 10349 RVA: 0x000ABCD1 File Offset: 0x000A9ED1
		public TerrainType EventTerrainType
		{
			get
			{
				return this._eventTerrainType;
			}
		}

		// Token: 0x17000A2E RID: 2606
		// (get) Token: 0x0600286E RID: 10350 RVA: 0x000ABCD9 File Offset: 0x000A9ED9
		// (set) Token: 0x0600286F RID: 10351 RVA: 0x000ABCE1 File Offset: 0x000A9EE1
		[SaveableProperty(113)]
		public bool IsInvulnerable { get; set; }

		// Token: 0x17000A2F RID: 2607
		// (get) Token: 0x06002870 RID: 10352 RVA: 0x000ABCEA File Offset: 0x000A9EEA
		public bool IsFieldBattle
		{
			get
			{
				return this._mapEventType == MapEvent.BattleTypes.FieldBattle;
			}
		}

		// Token: 0x17000A30 RID: 2608
		// (get) Token: 0x06002871 RID: 10353 RVA: 0x000ABCF5 File Offset: 0x000A9EF5
		public bool IsRaid
		{
			get
			{
				return this._mapEventType == MapEvent.BattleTypes.Raid;
			}
		}

		// Token: 0x17000A31 RID: 2609
		// (get) Token: 0x06002872 RID: 10354 RVA: 0x000ABD00 File Offset: 0x000A9F00
		public bool IsForcingVolunteers
		{
			get
			{
				return this._mapEventType == MapEvent.BattleTypes.IsForcingVolunteers;
			}
		}

		// Token: 0x17000A32 RID: 2610
		// (get) Token: 0x06002873 RID: 10355 RVA: 0x000ABD0B File Offset: 0x000A9F0B
		public bool IsForcingSupplies
		{
			get
			{
				return this._mapEventType == MapEvent.BattleTypes.IsForcingSupplies;
			}
		}

		// Token: 0x17000A33 RID: 2611
		// (get) Token: 0x06002874 RID: 10356 RVA: 0x000ABD16 File Offset: 0x000A9F16
		public bool IsSiegeAssault
		{
			get
			{
				return this._mapEventType == MapEvent.BattleTypes.Siege;
			}
		}

		// Token: 0x17000A34 RID: 2612
		// (get) Token: 0x06002875 RID: 10357 RVA: 0x000ABD21 File Offset: 0x000A9F21
		public bool IsHideoutBattle
		{
			get
			{
				return this._mapEventType == MapEvent.BattleTypes.Hideout;
			}
		}

		// Token: 0x17000A35 RID: 2613
		// (get) Token: 0x06002876 RID: 10358 RVA: 0x000ABD2C File Offset: 0x000A9F2C
		public bool IsSallyOut
		{
			get
			{
				return this._mapEventType == MapEvent.BattleTypes.SallyOut;
			}
		}

		// Token: 0x17000A36 RID: 2614
		// (get) Token: 0x06002877 RID: 10359 RVA: 0x000ABD37 File Offset: 0x000A9F37
		public bool IsSiegeOutside
		{
			get
			{
				return this._mapEventType == MapEvent.BattleTypes.SiegeOutside;
			}
		}

		// Token: 0x17000A37 RID: 2615
		// (get) Token: 0x06002878 RID: 10360 RVA: 0x000ABD42 File Offset: 0x000A9F42
		public bool IsSiegeAmbush
		{
			get
			{
				return this.Component is SiegeAmbushEventComponent;
			}
		}

		// Token: 0x06002879 RID: 10361 RVA: 0x000ABD52 File Offset: 0x000A9F52
		internal MapEvent()
		{
			this.MapEventVisual = Campaign.Current.VisualCreator.CreateMapEventVisual(this);
		}

		// Token: 0x0600287A RID: 10362 RVA: 0x000ABD88 File Offset: 0x000A9F88
		[LateLoadInitializationCallback]
		private void OnLateLoad(MetaData metaData, ObjectLoadData objectLoadData)
		{
			if (this.Component == null && MBSaveLoad.IsUpdatingGameVersion && MBSaveLoad.LastLoadedGameVersion < ApplicationVersion.FromString("v1.1.0", 54620))
			{
				if (this._mapEventType == MapEvent.BattleTypes.Raid)
				{
					float nextSettlementDamage = (float)objectLoadData.GetMemberValueBySaveId(109);
					int lootedItemCount = (int)objectLoadData.GetMemberValueBySaveId(112);
					float raidDamage = (float)objectLoadData.GetMemberValueBySaveId(115);
					this.Component = RaidEventComponent.CreateComponentForOldSaves(this, nextSettlementDamage, lootedItemCount, raidDamage);
				}
				else if (this._mapEventType == MapEvent.BattleTypes.IsForcingSupplies)
				{
					this.Component = ForceSuppliesEventComponent.CreateComponentForOldSaves(this);
				}
				else if (this._mapEventType == MapEvent.BattleTypes.IsForcingVolunteers)
				{
					this.Component = ForceVolunteersEventComponent.CreateComponentForOldSaves(this);
				}
				else if (this._mapEventType == MapEvent.BattleTypes.IsForcingVolunteers)
				{
					this.Component = HideoutEventComponent.CreateComponentForOldSaves(this);
				}
				else if (this._mapEventType == MapEvent.BattleTypes.FieldBattle)
				{
					this.Component = FieldBattleEventComponent.CreateComponentForOldSaves(this);
				}
			}
			MapEventComponent component = this.Component;
			if (component == null)
			{
				return;
			}
			component.AfterLoad(this);
		}

		// Token: 0x0600287B RID: 10363 RVA: 0x000ABE78 File Offset: 0x000AA078
		internal void OnAfterLoad()
		{
			this.CacheSimulationData();
			this._eventTerrainType = Campaign.Current.MapSceneWrapper.GetFaceTerrainType(Campaign.Current.MapSceneWrapper.GetFaceIndex(this.Position));
			if (!PartyBase.IsPositionOkForTraveling(this.Position))
			{
				Vec2 vec = this.CalculateMapEventPosition(this.AttackerSide.LeaderParty, this.DefenderSide.LeaderParty);
				if (vec != this.Position)
				{
					Vec2 v = vec - this.Position;
					foreach (PartyBase partyBase in this.InvolvedParties)
					{
						if (partyBase.IsMobile && partyBase.MobileParty.EventPositionAdder.IsNonZero())
						{
							partyBase.MobileParty.EventPositionAdder += v;
						}
					}
					this.Position = vec;
				}
			}
			if (!this.IsFinalized)
			{
				this.MapEventVisual = Campaign.Current.VisualCreator.CreateMapEventVisual(this);
				this.MapEventVisual.Initialize(this.Position, this.GetBattleSizeValue(), this.AttackerSide.LeaderParty != PartyBase.MainParty && this.DefenderSide.LeaderParty != PartyBase.MainParty, this.IsVisible);
			}
			if (MBSaveLoad.IsUpdatingGameVersion && MBSaveLoad.LastLoadedGameVersion < ApplicationVersion.FromString("v1.2.0", 54620))
			{
				if (!this.AttackerSide.Parties.Any<MapEventParty>() || !this.DefenderSide.Parties.Any<MapEventParty>())
				{
					if (this.InvolvedParties.ContainsQ(PlayerEncounter.EncounteredParty))
					{
						PlayerEncounter.Finish(true);
					}
					this.FinalizeEvent();
				}
				if (this.MapEventSettlement != null)
				{
					if (this.IsRaid && this.MapEventSettlement.Party.MapEvent == null)
					{
						this.FinalizeEvent();
						return;
					}
					if (this.EventType == MapEvent.BattleTypes.Siege && this.MapEventSettlement.SiegeEvent == null)
					{
						this.FinalizeEvent();
					}
				}
			}
		}

		// Token: 0x0600287C RID: 10364 RVA: 0x000AC088 File Offset: 0x000AA288
		internal void Initialize(PartyBase attackerParty, PartyBase defenderParty, MapEventComponent component = null, MapEvent.BattleTypes mapEventType = MapEvent.BattleTypes.None)
		{
			this.Component = component;
			this.FirstUpdateIsDone = false;
			this.AttackersRanAway = false;
			this.MapEventSettlement = null;
			this._mapEventType = mapEventType;
			this._mapEventUpdateCount = 0;
			this._sides[0] = new MapEventSide(this, BattleSideEnum.Defender, defenderParty);
			this._sides[1] = new MapEventSide(this, BattleSideEnum.Attacker, attackerParty);
			if (attackerParty.MobileParty == MobileParty.MainParty || defenderParty.MobileParty == MobileParty.MainParty)
			{
				if (mapEventType == MapEvent.BattleTypes.Raid)
				{
					Debug.Print("A raid mapEvent has been started on " + defenderParty.Name + "\n", 0, Debug.DebugColor.DarkGreen, 64UL);
				}
				else if (defenderParty.IsSettlement && defenderParty.Settlement.IsFortification)
				{
					Debug.Print("A siege mapEvent has been started on " + defenderParty.Name + "\n", 0, Debug.DebugColor.DarkCyan, 64UL);
				}
			}
			if (attackerParty.IsMobile && attackerParty.MobileParty.CurrentSettlement != null)
			{
				this.MapEventSettlement = attackerParty.MobileParty.CurrentSettlement;
			}
			else if (defenderParty.IsMobile && defenderParty.MobileParty.CurrentSettlement != null)
			{
				this.MapEventSettlement = defenderParty.MobileParty.CurrentSettlement;
			}
			else if ((!attackerParty.IsMobile || attackerParty.MobileParty.BesiegedSettlement == null) && defenderParty.IsMobile)
			{
				Settlement besiegedSettlement = defenderParty.MobileParty.BesiegedSettlement;
			}
			if (attackerParty.IsSettlement)
			{
				this.MapEventSettlement = attackerParty.Settlement;
			}
			else if (defenderParty.IsSettlement)
			{
				this.MapEventSettlement = defenderParty.Settlement;
				this.MapEventSettlement.LastAttackerParty = attackerParty.MobileParty;
			}
			if (this.IsFieldBattle)
			{
				this.MapEventSettlement = null;
				if (attackerParty == PartyBase.MainParty || defenderParty == PartyBase.MainParty)
				{
					Settlement settlement = SettlementHelper.FindNearestVillage((Settlement x) => x.Position2D.DistanceSquared(attackerParty.Position2D) < 9f, null);
					if (settlement != null)
					{
						this.MapEventSettlement = settlement;
					}
				}
			}
			this.Position = this.CalculateMapEventPosition(attackerParty, defenderParty);
			this._eventTerrainType = Campaign.Current.MapSceneWrapper.GetFaceTerrainType(Campaign.Current.MapSceneWrapper.GetFaceIndex(this.Position));
			this.CacheSimulationData();
			attackerParty.MapEventSide = this.AttackerSide;
			defenderParty.MapEventSide = this.DefenderSide;
			if (this.MapEventSettlement != null && (mapEventType == MapEvent.BattleTypes.Siege || mapEventType == MapEvent.BattleTypes.SiegeOutside || mapEventType == MapEvent.BattleTypes.SallyOut || this.IsSiegeAmbush))
			{
				foreach (PartyBase partyBase in this.MapEventSettlement.SiegeEvent.BesiegerCamp.GetInvolvedPartiesForEventType(mapEventType))
				{
					if (partyBase.MapEventSide == null && (partyBase != PartyBase.MainParty || partyBase.MobileParty.Army != null) && (partyBase.MobileParty.Army == null || partyBase.MobileParty.Army.LeaderParty == partyBase.MobileParty))
					{
						partyBase.MapEventSide = ((mapEventType == MapEvent.BattleTypes.SallyOut) ? defenderParty.MapEventSide : attackerParty.MapEventSide);
					}
				}
			}
			if (defenderParty.IsMobile && defenderParty.MobileParty.BesiegedSettlement != null)
			{
				List<PartyBase> involvedPartiesForEventType = defenderParty.MobileParty.SiegeEvent.GetInvolvedPartiesForEventType(this._mapEventType);
				PartyBase partyBase2 = this.IsSiegeAssault ? attackerParty : defenderParty;
				foreach (PartyBase partyBase3 in involvedPartiesForEventType)
				{
					if (partyBase3 != partyBase2 && partyBase3.IsMobile && partyBase3 != PartyBase.MainParty && partyBase3.MobileParty.BesiegedSettlement == defenderParty.MobileParty.BesiegedSettlement && (partyBase3.MobileParty.Army == null || partyBase3.MobileParty.Army.LeaderParty == partyBase3.MobileParty))
					{
						partyBase3.MapEventSide = this.DefenderSide;
					}
				}
			}
			this.State = MapEventState.Wait;
			this._mapEventStartTime = CampaignTime.Now;
			this._nextSimulationTime = MapEvent.CalculateNextSimulationTime();
			MapEventComponent component2 = this.Component;
			if (component2 != null)
			{
				component2.InitializeComponent();
			}
			if (this.MapEventSettlement != null)
			{
				this.AddInsideSettlementParties(this.MapEventSettlement);
			}
			this.MapEventVisual.Initialize(this.Position, this.GetBattleSizeValue(), this.AttackerSide.LeaderParty != PartyBase.MainParty && this.DefenderSide.LeaderParty != PartyBase.MainParty, this.IsVisible);
			this.BattleState = BattleState.None;
			CampaignEventDispatcher.Instance.OnMapEventStarted(this, attackerParty, defenderParty);
		}

		// Token: 0x0600287D RID: 10365 RVA: 0x000AC53C File Offset: 0x000AA73C
		private Vec2 CalculateMapEventPosition(PartyBase attackerParty, PartyBase defenderParty)
		{
			Vec2 vec;
			if (defenderParty.IsSettlement)
			{
				vec = defenderParty.Position2D;
			}
			else
			{
				vec = attackerParty.Position2D + defenderParty.Position2D;
				vec = new Vec2(vec.x / 2f, vec.y / 2f);
			}
			return vec;
		}

		// Token: 0x0600287E RID: 10366 RVA: 0x000AC58C File Offset: 0x000AA78C
		internal bool IsWinnerSide(BattleSideEnum side)
		{
			return (this.BattleState == BattleState.DefenderVictory && side == BattleSideEnum.Defender) || (this.BattleState == BattleState.AttackerVictory && side == BattleSideEnum.Attacker);
		}

		// Token: 0x0600287F RID: 10367 RVA: 0x000AC5AC File Offset: 0x000AA7AC
		private void AddInsideSettlementParties(Settlement relatedSettlement)
		{
			List<PartyBase> list = new List<PartyBase>();
			foreach (PartyBase partyBase in relatedSettlement.GetInvolvedPartiesForEventType(this._mapEventType))
			{
				if (partyBase != PartyBase.MainParty)
				{
					MobileParty mobileParty = partyBase.MobileParty;
					if (((mobileParty != null) ? mobileParty.AttachedTo : null) != MobileParty.MainParty)
					{
						list.Add(partyBase);
					}
				}
			}
			foreach (PartyBase partyBase2 in list)
			{
				if (this.MapEventSettlement.SiegeEvent != null)
				{
					if (this.MapEventSettlement.SiegeEvent.CanPartyJoinSide(partyBase2, BattleSideEnum.Defender))
					{
						if (this.IsSallyOut)
						{
							partyBase2.MapEventSide = this.AttackerSide;
						}
						else
						{
							partyBase2.MapEventSide = this.DefenderSide;
						}
					}
					else if (partyBase2.MobileParty != null && !partyBase2.MobileParty.IsGarrison && !partyBase2.MobileParty.IsMilitia)
					{
						LeaveSettlementAction.ApplyForParty(partyBase2.MobileParty);
						partyBase2.MobileParty.Ai.SetMoveModeHold();
					}
				}
				else if (this.CanPartyJoinBattle(partyBase2, BattleSideEnum.Defender))
				{
					partyBase2.MapEventSide = this.DefenderSide;
				}
				else if (this.CanPartyJoinBattle(partyBase2, BattleSideEnum.Attacker))
				{
					partyBase2.MapEventSide = this.AttackerSide;
				}
				else if (partyBase2.MobileParty != null && !partyBase2.MobileParty.IsGarrison && !partyBase2.MobileParty.IsMilitia)
				{
					LeaveSettlementAction.ApplyForParty(partyBase2.MobileParty);
				}
			}
		}

		// Token: 0x06002880 RID: 10368 RVA: 0x000AC780 File Offset: 0x000AA980
		private int GetBattleSizeValue()
		{
			if (this.IsSiegeAssault)
			{
				return 4;
			}
			int numberOfInvolvedMen = this.GetNumberOfInvolvedMen();
			if (numberOfInvolvedMen < 30)
			{
				return 0;
			}
			if (numberOfInvolvedMen < 80)
			{
				return 1;
			}
			if (numberOfInvolvedMen >= 120)
			{
				return 3;
			}
			return 2;
		}

		// Token: 0x06002881 RID: 10369 RVA: 0x000AC7B4 File Offset: 0x000AA9B4
		private static CampaignTime CalculateNextSimulationTime()
		{
			return CampaignTime.Now + CampaignTime.Minutes(30L);
		}

		// Token: 0x06002882 RID: 10370 RVA: 0x000AC7C8 File Offset: 0x000AA9C8
		internal void AddInvolvedPartyInternal(PartyBase involvedParty, BattleSideEnum side)
		{
			if (involvedParty.LeaderHero != null && involvedParty.LeaderHero.Clan == Clan.PlayerClan && involvedParty != PartyBase.MainParty && side == BattleSideEnum.Defender && this.AttackerSide.LeaderParty != null)
			{
				bool flag = false;
				using (IEnumerator<PartyBase> enumerator = this.InvolvedParties.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						if (enumerator.Current == PartyBase.MainParty)
						{
							flag = true;
							break;
						}
					}
				}
				if (!flag)
				{
					Settlement settlement = Hero.MainHero.HomeSettlement;
					float num = Campaign.MapDiagonalSquared;
					foreach (Settlement settlement2 in Settlement.All)
					{
						if (settlement2.IsVillage || settlement2.IsFortification)
						{
							float num2 = settlement2.Position2D.DistanceSquared(involvedParty.Position2D);
							if (num2 < num)
							{
								num = num2;
								settlement = settlement2;
							}
						}
					}
					if (settlement != null)
					{
						TextObject textObject = GameTexts.FindText("str_party_attacked", null);
						textObject.SetTextVariable("CLAN_PARTY_NAME", involvedParty.Name);
						textObject.SetTextVariable("ENEMY_PARTY_NAME", this.AttackerSide.LeaderParty.Name);
						textObject.SetTextVariable("SETTLEMENT_NAME", settlement.Name);
						MBInformationManager.AddQuickInformation(textObject, 0, null, "");
					}
				}
			}
			if (this.IsSiegeAssault && involvedParty.MobileParty != null && involvedParty.MobileParty.CurrentSettlement == null && side == BattleSideEnum.Defender)
			{
				this._mapEventType = MapEvent.BattleTypes.SiegeOutside;
			}
			if (involvedParty.MobileParty != null && involvedParty.MobileParty.IsGarrison && side == BattleSideEnum.Attacker && this.IsSiegeOutside)
			{
				this._mapEventType = MapEvent.BattleTypes.SallyOut;
				this.MapEventSettlement = involvedParty.MobileParty.CurrentSettlement;
			}
			involvedParty.ResetTempXp();
			if (involvedParty == MobileParty.MainParty.Party && !this.IsSiegeAssault && !this.IsRaid)
			{
				involvedParty.MobileParty.Ai.SetMoveModeHold();
			}
			if (involvedParty == PartyBase.MainParty)
			{
				involvedParty.MobileParty.Ai.ForceAiNoPathMode = false;
			}
			this.RecalculateRenownAndInfluenceValues(involvedParty);
			if (this.IsFieldBattle && involvedParty.IsMobile && involvedParty.MobileParty.BesiegedSettlement == null)
			{
				Vec2 v = this.GetMapEventSide(side).LeaderParty.Position2D - this.Position;
				float a = v.Normalize();
				if (involvedParty != this.GetMapEventSide(side).LeaderParty)
				{
					int num3 = this.GetMapEventSide(side).Parties.Count((MapEventParty p) => p.Party.IsMobile) - 1;
					involvedParty.MobileParty.EventPositionAdder = this.Position + v * MathF.Max(a, 0.4f) + (float)((num3 + 1) / 2 * ((num3 % 2 == 0) ? 1 : -1)) * v.RightVec() * 0.4f - (involvedParty.Position2D + involvedParty.MobileParty.ArmyPositionAdder);
				}
				else
				{
					involvedParty.MobileParty.EventPositionAdder = this.Position + v * MathF.Max(a, 0.4f) - (involvedParty.Position2D + involvedParty.MobileParty.ArmyPositionAdder);
				}
			}
			involvedParty.SetVisualAsDirty();
			if (involvedParty.IsMobile && involvedParty.MobileParty.Army != null && involvedParty.MobileParty.Army.LeaderParty == involvedParty.MobileParty)
			{
				foreach (MobileParty mobileParty in involvedParty.MobileParty.Army.LeaderParty.AttachedParties)
				{
					mobileParty.Party.SetVisualAsDirty();
				}
			}
			if (this.HasWinner && involvedParty.MapEventSide.MissionSide != this.WinningSide && involvedParty.NumberOfHealthyMembers > 0)
			{
				this.BattleState = BattleState.None;
			}
			if (involvedParty.IsVisible)
			{
				this.IsVisible = true;
			}
			this.ResetUnsuitablePartiesThatWereTargetingThisMapEvent();
		}

		// Token: 0x17000A38 RID: 2616
		// (get) Token: 0x06002883 RID: 10371 RVA: 0x000ACC04 File Offset: 0x000AAE04
		// (set) Token: 0x06002884 RID: 10372 RVA: 0x000ACC0C File Offset: 0x000AAE0C
		public bool IsVisible
		{
			get
			{
				return this._isVisible;
			}
			private set
			{
				this._isVisible = value;
				IMapEventVisual mapEventVisual = this.MapEventVisual;
				if (mapEventVisual == null)
				{
					return;
				}
				mapEventVisual.SetVisibility(value);
			}
		}

		// Token: 0x06002885 RID: 10373 RVA: 0x000ACC28 File Offset: 0x000AAE28
		internal void PartyVisibilityChanged(PartyBase party, bool isPartyVisible)
		{
			if (isPartyVisible)
			{
				this.IsVisible = true;
				return;
			}
			bool isVisible = false;
			foreach (PartyBase partyBase in this.InvolvedParties)
			{
				if (partyBase != party && partyBase.IsVisible)
				{
					isVisible = true;
					break;
				}
			}
			this.IsVisible = isVisible;
		}

		// Token: 0x06002886 RID: 10374 RVA: 0x000ACC94 File Offset: 0x000AAE94
		internal void RemoveInvolvedPartyInternal(PartyBase party)
		{
			party.SetVisualAsDirty();
			if (party.IsMobile && party.MobileParty.Army != null && party.MobileParty.Army.LeaderParty == party.MobileParty)
			{
				foreach (MobileParty mobileParty in party.MobileParty.Army.LeaderParty.AttachedParties)
				{
					mobileParty.Party.SetVisualAsDirty();
				}
			}
			if (this.IsFieldBattle && party.IsMobile)
			{
				party.MobileParty.EventPositionAdder = Vec2.Zero;
				foreach (MapEventSide mapEventSide in this._sides)
				{
					MapEventParty[] array = mapEventSide.Parties.ToArray();
					Vec2 v = mapEventSide.LeaderParty.Position2D - this.Position;
					float a = v.Normalize();
					for (int j = 0; j < array.Length; j++)
					{
						PartyBase party2 = array[j].Party;
						if (party2.IsMobile && party2 != mapEventSide.LeaderParty)
						{
							party2.MobileParty.EventPositionAdder = this.Position + v * MathF.Max(a, 0.4f) + (float)((j + 1) / 2 * ((j % 2 == 0) ? 1 : -1)) * v.RightVec() * 0.4f - (party2.Position2D + party2.MobileParty.ArmyPositionAdder);
						}
					}
				}
			}
			if (this.IsSiegeOutside)
			{
				MapEventSide mapEventSide2;
				if (this.MapEventSettlement == null)
				{
					mapEventSide2 = this.AttackerSide;
				}
				else
				{
					mapEventSide2 = this.DefenderSide;
				}
				if (mapEventSide2.Parties.All((MapEventParty x) => x.Party.MobileParty == null || (this.MapEventSettlement != null && x.Party.MobileParty.CurrentSettlement == this.MapEventSettlement)) && this.MapEventSettlement != null)
				{
					this._mapEventType = MapEvent.BattleTypes.Siege;
				}
			}
			if (party == PartyBase.MainParty && this.State == MapEventState.Wait)
			{
				this.AttackerSide.RemoveNearbyPartiesFromPlayerMapEvent();
				this.DefenderSide.RemoveNearbyPartiesFromPlayerMapEvent();
			}
			if (party.IsVisible)
			{
				this.PartyVisibilityChanged(party, false);
			}
			this.ResetUnsuitablePartiesThatWereTargetingThisMapEvent();
			if (party.IsMobile && !party.MobileParty.IsCurrentlyUsedByAQuest && party.SiegeEvent == null && (party.MobileParty.Army == null || party.MobileParty.Army.LeaderParty == party.MobileParty))
			{
				party.MobileParty.Ai.SetMoveModeHold();
			}
		}

		// Token: 0x06002887 RID: 10375 RVA: 0x000ACF24 File Offset: 0x000AB124
		public int GetNumberOfInvolvedMen()
		{
			return this.DefenderSide.RecalculateMemberCountOfSide() + this.AttackerSide.RecalculateMemberCountOfSide();
		}

		// Token: 0x06002888 RID: 10376 RVA: 0x000ACF3D File Offset: 0x000AB13D
		public int GetNumberOfInvolvedMen(BattleSideEnum side)
		{
			return this.GetMapEventSide(side).RecalculateMemberCountOfSide();
		}

		// Token: 0x06002889 RID: 10377 RVA: 0x000ACF4B File Offset: 0x000AB14B
		private void LootDefeatedParties(out bool playerCaptured, LootCollector lootCollector)
		{
			this.GetMapEventSide(this.DefeatedSide).CollectAll(lootCollector, out playerCaptured);
		}

		// Token: 0x0600288A RID: 10378 RVA: 0x000ACF60 File Offset: 0x000AB160
		internal void AddCasualtiesInBattle(TroopRoster troopRoster, LootCollector lootCollector)
		{
			lootCollector.CasualtiesInBattle.Add(troopRoster);
		}

		// Token: 0x0600288B RID: 10379 RVA: 0x000ACF70 File Offset: 0x000AB170
		private int CalculatePlunderedGold()
		{
			float num = 0f;
			foreach (MapEventParty mapEventParty in this.GetMapEventSide(this.DefeatedSide).Parties)
			{
				PartyBase party = mapEventParty.Party;
				if (party.LeaderHero != null)
				{
					int num2 = Campaign.Current.Models.BattleRewardModel.CalculateGoldLossAfterDefeat(party.LeaderHero);
					num += (float)num2;
					mapEventParty.GoldLost = num2;
				}
				else if (party.IsMobile && party.MobileParty.IsPartyTradeActive)
				{
					int num3 = (int)(party.MobileParty.IsBandit ? ((float)party.MobileParty.PartyTradeGold * 0.5f) : ((float)party.MobileParty.PartyTradeGold * 0.1f));
					num += (float)num3;
					mapEventParty.GoldLost = num3;
				}
			}
			return (int)num;
		}

		// Token: 0x0600288C RID: 10380 RVA: 0x000AD06C File Offset: 0x000AB26C
		private void CalculateRenownShares(MapEventResultExplainer resultExplainers = null, bool forScoreboard = false)
		{
			if (this.BattleState == BattleState.AttackerVictory || this.BattleState == BattleState.DefenderVictory)
			{
				((this.BattleState == BattleState.AttackerVictory) ? this.AttackerSide : this.DefenderSide).DistributeRenownAndInfluence(resultExplainers, forScoreboard);
			}
		}

		// Token: 0x0600288D RID: 10381 RVA: 0x000AD09E File Offset: 0x000AB29E
		private void CalculateLootShares(LootCollector lootCollector)
		{
			if (this.BattleState == BattleState.AttackerVictory || this.BattleState == BattleState.DefenderVictory)
			{
				((this.BattleState == BattleState.AttackerVictory) ? this.AttackerSide : this.DefenderSide).DistributeLootAmongWinners(lootCollector);
			}
		}

		// Token: 0x0600288E RID: 10382 RVA: 0x000AD0CF File Offset: 0x000AB2CF
		private int GetSimulatedDamage(CharacterObject strikerTroop, CharacterObject strikedTroop, PartyBase strikerParty, PartyBase strikedParty, float strikerAdvantage)
		{
			return Campaign.Current.Models.CombatSimulationModel.SimulateHit(strikerTroop, strikedTroop, strikerParty, strikedParty, strikerAdvantage, this);
		}

		// Token: 0x0600288F RID: 10383 RVA: 0x000AD0F0 File Offset: 0x000AB2F0
		private void SimulateBattleForRound(BattleSideEnum side, float advantage)
		{
			bool flag = this.AttackerSide.NumRemainingSimulationTroops == 0 || this.DefenderSide.NumRemainingSimulationTroops == 0 || this.SimulateSingleHit((int)side, (int)(BattleSideEnum.Attacker - side), advantage);
			if (flag)
			{
				bool flag2 = false;
				BattleState calculateWinner = this.GetCalculateWinner(ref flag2);
				if (calculateWinner != BattleState.None)
				{
					this.BattleState = calculateWinner;
					return;
				}
				if (flag2)
				{
					IBattleObserver battleObserver = this.BattleObserver;
					if (battleObserver == null)
					{
						return;
					}
					battleObserver.BattleResultsReady();
				}
			}
		}

		// Token: 0x06002890 RID: 10384 RVA: 0x000AD158 File Offset: 0x000AB358
		private bool SimulateSingleHit(int strikerSideIndex, int strikedSideIndex, float strikerAdvantage)
		{
			MapEventSide mapEventSide = this._sides[strikerSideIndex];
			MapEventSide mapEventSide2 = this._sides[strikedSideIndex];
			UniqueTroopDescriptor uniqueTroopDescriptor = mapEventSide.SelectRandomSimulationTroop();
			UniqueTroopDescriptor uniqueTroopDescriptor2 = mapEventSide2.SelectRandomSimulationTroop();
			CharacterObject allocatedTroop = mapEventSide.GetAllocatedTroop(uniqueTroopDescriptor);
			CharacterObject allocatedTroop2 = mapEventSide2.GetAllocatedTroop(uniqueTroopDescriptor2);
			PartyBase allocatedTroopParty = mapEventSide.GetAllocatedTroopParty(uniqueTroopDescriptor);
			PartyBase allocatedTroopParty2 = mapEventSide2.GetAllocatedTroopParty(uniqueTroopDescriptor2);
			int num = this.GetSimulatedDamage(allocatedTroop, allocatedTroop2, allocatedTroopParty, allocatedTroopParty2, strikerAdvantage);
			if (num > 0)
			{
				if (this.IsPlayerSimulation && allocatedTroopParty2 == PartyBase.MainParty)
				{
					float playerTroopsReceivedDamageMultiplier = Campaign.Current.Models.DifficultyModel.GetPlayerTroopsReceivedDamageMultiplier();
					num = MBRandom.RoundRandomized((float)num * playerTroopsReceivedDamageMultiplier);
				}
				DamageTypes damageType = (MBRandom.RandomFloat < 0.3f) ? DamageTypes.Blunt : DamageTypes.Cut;
				bool flag = mapEventSide2.ApplySimulationDamageToSelectedTroop(num, damageType, allocatedTroopParty);
				mapEventSide.ApplySimulatedHitRewardToSelectedTroop(allocatedTroop, allocatedTroop2, num, flag);
				if (this.IsPlayerSimulation && allocatedTroopParty == PartyBase.MainParty && flag)
				{
					CampaignEventDispatcher.Instance.OnPlayerPartyKnockedOrKilledTroop(allocatedTroop2);
				}
				return flag;
			}
			return false;
		}

		// Token: 0x06002891 RID: 10385 RVA: 0x000AD250 File Offset: 0x000AB450
		private bool GetAttackersRunAwayChance()
		{
			if (this._mapEventUpdateCount <= 1)
			{
				return false;
			}
			if (this.AttackerSide.LeaderParty.LeaderHero == null)
			{
				return false;
			}
			if (this.IsSallyOut)
			{
				return false;
			}
			float num = 0f;
			foreach (MapEventParty mapEventParty in this.AttackerSide.Parties)
			{
				num += mapEventParty.Party.TotalStrength;
			}
			float num2 = 0f;
			foreach (MapEventParty mapEventParty2 in this.DefenderSide.Parties)
			{
				num2 += mapEventParty2.Party.TotalStrength;
			}
			if (this.IsSiegeAssault)
			{
				num *= 0.6666667f;
			}
			if (num2 > num * 1.1f)
			{
				float randomFloat = MBRandom.RandomFloat;
				float num3 = (this._mapEventUpdateCount < 16) ? MathF.Sqrt((float)this._mapEventUpdateCount / 16f) : 1f;
				return randomFloat * num3 > num / (num2 * 1.1f);
			}
			return false;
		}

		// Token: 0x06002892 RID: 10386 RVA: 0x000AD388 File Offset: 0x000AB588
		internal void Update()
		{
			if (this._isFinishCalled)
			{
				return;
			}
			bool flag = false;
			if (this._sides[0].LeaderParty == null || this._sides[1].LeaderParty == null || !this._sides[0].LeaderParty.MapFaction.IsAtWarWith(this._sides[1].LeaderParty.MapFaction))
			{
				this.DiplomaticallyFinished = true;
			}
			if (!this.DiplomaticallyFinished)
			{
				MapEventComponent component = this.Component;
				if (component != null)
				{
					component.Update(ref flag);
				}
				if (((this.DefenderSide.TroopCount > 0 && this.AttackerSide.TroopCount > 0) || (!this.FirstUpdateIsDone && (this.DefenderSide.TroopCount > 0 || this._mapEventType != MapEvent.BattleTypes.Raid))) && this._nextSimulationTime.IsPast)
				{
					this.AttackersRanAway = (this._mapEventType != MapEvent.BattleTypes.Siege && this._mapEventType != MapEvent.BattleTypes.SallyOut && this._mapEventType != MapEvent.BattleTypes.SiegeOutside && this._mapEventType != MapEvent.BattleTypes.Raid && this.GetAttackersRunAwayChance());
					this._mapEventUpdateCount++;
					if (!this.AttackersRanAway)
					{
						this.SimulateBattleSessionForMapEvent();
						this._nextSimulationTime = MapEvent.CalculateNextSimulationTime();
						this.FirstUpdateIsDone = true;
					}
					else
					{
						flag = true;
					}
				}
				if ((this._mapEventType != MapEvent.BattleTypes.Raid || this.DefenderSide.Parties.Count > 1) && this.BattleState != BattleState.None)
				{
					flag = true;
				}
			}
			else
			{
				flag = true;
				foreach (PartyBase partyBase in this.InvolvedParties)
				{
					if (partyBase.IsMobile && partyBase.MobileParty != MobileParty.MainParty && (partyBase.MobileParty.Army == null || partyBase.MobileParty.Army.LeaderParty == partyBase.MobileParty))
					{
						partyBase.MobileParty.Ai.RecalculateShortTermAi();
					}
				}
			}
			if (flag)
			{
				MapEventComponent component2 = this.Component;
				if (component2 != null)
				{
					component2.Finish();
				}
				if (!this.IsPlayerMapEvent || PlayerEncounter.Current == null)
				{
					this.FinishBattle();
				}
			}
		}

		// Token: 0x06002893 RID: 10387 RVA: 0x000AD598 File Offset: 0x000AB798
		public void FinishBattleAndKeepSiegeEvent()
		{
			this._keepSiegeEvent = true;
			this.FinishBattle();
		}

		// Token: 0x06002894 RID: 10388 RVA: 0x000AD5A8 File Offset: 0x000AB7A8
		private void CheckSiegeStageChange()
		{
			if (this.MapEventSettlement != null && this.IsSiegeAssault)
			{
				bool flag = this.AttackerSide.Parties.Sum((MapEventParty party) => party.Party.NumberOfHealthyMembers) != 0;
				int num = this.DefenderSide.Parties.Sum((MapEventParty party) => party.Party.NumberOfHealthyMembers);
				if (flag)
				{
				}
				return;
			}
		}

		// Token: 0x06002895 RID: 10389 RVA: 0x000AD62C File Offset: 0x000AB82C
		public void SimulateBattleSetup(FlattenedTroopRoster[] priorTroops)
		{
			if (this.IsSiegeAssault)
			{
				this.CheckSiegeStageChange();
			}
			foreach (MapEventSide mapEventSide in this._sides)
			{
				FlattenedTroopRoster flattenedTroopRoster = (priorTroops != null) ? priorTroops[(int)mapEventSide.MissionSide] : null;
				mapEventSide.MakeReadyForSimulation(flattenedTroopRoster, (flattenedTroopRoster != null) ? flattenedTroopRoster.Count<FlattenedTroopRosterElement>() : -1);
			}
			this._battleState = BattleState.None;
		}

		// Token: 0x06002896 RID: 10390 RVA: 0x000AD68C File Offset: 0x000AB88C
		public void SimulateBattleForRounds(int simulationRoundsDefender, int simulationRoundsAttacker)
		{
			bool flag = false;
			this.BattleState = this.GetCalculateWinner(ref flag);
			ValueTuple<float, float> battleAdvantage = Campaign.Current.Models.CombatSimulationModel.GetBattleAdvantage(this.DefenderSide.LeaderParty, this.AttackerSide.LeaderParty, this._mapEventType, this.MapEventSettlement);
			float item = battleAdvantage.Item1;
			float item2 = battleAdvantage.Item2;
			int num = 0;
			while (0 < simulationRoundsAttacker + simulationRoundsDefender && this.BattleState == BattleState.None)
			{
				float num2 = (float)simulationRoundsAttacker / (float)(simulationRoundsAttacker + simulationRoundsDefender);
				if (MBRandom.RandomFloat < num2)
				{
					simulationRoundsAttacker--;
					this.SimulateBattleForRound(BattleSideEnum.Attacker, item2);
				}
				else
				{
					simulationRoundsDefender--;
					this.SimulateBattleForRound(BattleSideEnum.Defender, item);
				}
				num++;
			}
		}

		// Token: 0x06002897 RID: 10391 RVA: 0x000AD730 File Offset: 0x000AB930
		private void SimulateBattleSessionForMapEvent()
		{
			this.SimulateBattleSetup(null);
			ValueTuple<int, int> simulationRoundsForBattle = Campaign.Current.Models.CombatSimulationModel.GetSimulationRoundsForBattle(this, this.DefenderSide.NumRemainingSimulationTroops, this.AttackerSide.NumRemainingSimulationTroops);
			int item = simulationRoundsForBattle.Item1;
			int item2 = simulationRoundsForBattle.Item2;
			this.SimulateBattleForRounds(item, item2);
			this.SimulateBattleEndSession();
		}

		// Token: 0x06002898 RID: 10392 RVA: 0x000AD78C File Offset: 0x000AB98C
		internal void SimulatePlayerEncounterBattle()
		{
			ValueTuple<int, int> simulationRoundsForBattle = Campaign.Current.Models.CombatSimulationModel.GetSimulationRoundsForBattle(this, this.DefenderSide.NumRemainingSimulationTroops, this.AttackerSide.NumRemainingSimulationTroops);
			int item = simulationRoundsForBattle.Item1;
			int item2 = simulationRoundsForBattle.Item2;
			this.SimulateBattleForRounds(item, item2);
		}

		// Token: 0x06002899 RID: 10393 RVA: 0x000AD7DC File Offset: 0x000AB9DC
		private void SimulateBattleEndSession()
		{
			this.CommitXpGains();
			this.ApplyRenownAndInfluenceChanges();
			this.ApplyRewardsAndChanges();
			MapEventSide[] sides = this._sides;
			for (int i = 0; i < sides.Length; i++)
			{
				sides[i].EndSimulation();
			}
		}

		// Token: 0x17000A39 RID: 2617
		// (get) Token: 0x0600289A RID: 10394 RVA: 0x000AD818 File Offset: 0x000ABA18
		public bool IsPlayerMapEvent
		{
			get
			{
				return this == MapEvent.PlayerMapEvent;
			}
		}

		// Token: 0x17000A3A RID: 2618
		// (get) Token: 0x0600289B RID: 10395 RVA: 0x000AD822 File Offset: 0x000ABA22
		public bool IsFinished
		{
			get
			{
				return this._state == MapEventState.WaitingRemoval;
			}
		}

		// Token: 0x17000A3B RID: 2619
		// (get) Token: 0x0600289C RID: 10396 RVA: 0x000AD82D File Offset: 0x000ABA2D
		// (set) Token: 0x0600289D RID: 10397 RVA: 0x000AD838 File Offset: 0x000ABA38
		public BattleState BattleState
		{
			get
			{
				return this._battleState;
			}
			internal set
			{
				if (value != this._battleState)
				{
					if (this.IsPlayerMapEvent)
					{
						Debug.Print("Player MapEvent BattleState: " + value.ToString(), 0, Debug.DebugColor.White, 17592186044416UL);
					}
					this._battleState = value;
					if (this._battleState == BattleState.AttackerVictory || this._battleState == BattleState.DefenderVictory)
					{
						this.OnBattleWon(this._battleState);
					}
				}
			}
		}

		// Token: 0x17000A3C RID: 2620
		// (get) Token: 0x0600289E RID: 10398 RVA: 0x000AD8A3 File Offset: 0x000ABAA3
		public MapEventSide Winner
		{
			get
			{
				if (this.BattleState == BattleState.AttackerVictory)
				{
					return this.AttackerSide;
				}
				if (this.BattleState != BattleState.DefenderVictory)
				{
					return null;
				}
				return this.DefenderSide;
			}
		}

		// Token: 0x0600289F RID: 10399 RVA: 0x000AD8C6 File Offset: 0x000ABAC6
		private void OnBattleWon(BattleState winnerSide)
		{
			this.CalculateBattleResults(true);
			IBattleObserver battleObserver = this.BattleObserver;
			if (battleObserver == null)
			{
				return;
			}
			battleObserver.BattleResultsReady();
		}

		// Token: 0x17000A3D RID: 2621
		// (get) Token: 0x060028A0 RID: 10400 RVA: 0x000AD8DF File Offset: 0x000ABADF
		public BattleSideEnum WinningSide
		{
			get
			{
				if (this.BattleState == BattleState.AttackerVictory)
				{
					return BattleSideEnum.Attacker;
				}
				if (this.BattleState != BattleState.DefenderVictory)
				{
					return BattleSideEnum.None;
				}
				return BattleSideEnum.Defender;
			}
		}

		// Token: 0x17000A3E RID: 2622
		// (get) Token: 0x060028A1 RID: 10401 RVA: 0x000AD8F8 File Offset: 0x000ABAF8
		public BattleSideEnum DefeatedSide
		{
			get
			{
				if (this.BattleState == BattleState.AttackerVictory)
				{
					return BattleSideEnum.Defender;
				}
				if (this.BattleState != BattleState.DefenderVictory)
				{
					return BattleSideEnum.None;
				}
				return BattleSideEnum.Attacker;
			}
		}

		// Token: 0x060028A2 RID: 10402 RVA: 0x000AD914 File Offset: 0x000ABB14
		private BattleState GetCalculateWinner(ref bool isRoundWinnerDetermined)
		{
			BattleState result = BattleState.None;
			int num = this.AttackerSide.NumRemainingSimulationTroops;
			int num2 = this.DefenderSide.NumRemainingSimulationTroops;
			if (this.IsPlayerSimulation && !Hero.MainHero.IsWounded && this.InvolvedParties.Contains(PartyBase.MainParty))
			{
				if (PartyBase.MainParty.Side == BattleSideEnum.Attacker)
				{
					if (num == 0)
					{
						isRoundWinnerDetermined = true;
					}
					num++;
				}
				else if (PartyBase.MainParty.Side == BattleSideEnum.Defender)
				{
					if (num2 == 0)
					{
						isRoundWinnerDetermined = true;
					}
					num2++;
				}
			}
			if (num == 0)
			{
				result = BattleState.DefenderVictory;
			}
			else if (num2 == 0)
			{
				result = BattleState.AttackerVictory;
			}
			return result;
		}

		// Token: 0x060028A3 RID: 10403 RVA: 0x000AD99D File Offset: 0x000ABB9D
		public void SetOverrideWinner(BattleSideEnum winner)
		{
			this.BattleState = ((winner == BattleSideEnum.Attacker) ? BattleState.AttackerVictory : ((winner == BattleSideEnum.Defender) ? BattleState.DefenderVictory : BattleState.None));
		}

		// Token: 0x060028A4 RID: 10404 RVA: 0x000AD9B3 File Offset: 0x000ABBB3
		public void SetDefenderPulledBack()
		{
			this.BattleState = BattleState.DefenderPullBack;
		}

		// Token: 0x060028A5 RID: 10405 RVA: 0x000AD9BC File Offset: 0x000ABBBC
		public void ResetBattleState()
		{
			this.BattleState = BattleState.None;
		}

		// Token: 0x060028A6 RID: 10406 RVA: 0x000AD9C8 File Offset: 0x000ABBC8
		internal bool CheckIfOneSideHasLost()
		{
			int num = this.DefenderSide.RecalculateMemberCountOfSide();
			int num2 = this.AttackerSide.RecalculateMemberCountOfSide();
			if (this.BattleState == BattleState.None && (num == 0 || num2 == 0))
			{
				this.BattleState = ((num2 > 0) ? BattleState.AttackerVictory : BattleState.DefenderVictory);
			}
			return this.BattleState == BattleState.AttackerVictory || this.BattleState == BattleState.DefenderVictory;
		}

		// Token: 0x060028A7 RID: 10407 RVA: 0x000ADA1D File Offset: 0x000ABC1D
		internal ItemRoster ItemRosterForPlayerLootShare(PartyBase party)
		{
			return this.GetMapEventSide(party.Side).ItemRosterForPlayerLootShare(party);
		}

		// Token: 0x060028A8 RID: 10408 RVA: 0x000ADA34 File Offset: 0x000ABC34
		public bool IsPlayerSergeant()
		{
			return this.IsPlayerMapEvent && this.GetLeaderParty(this.PlayerSide) != PartyBase.MainParty && MobileParty.MainParty.Army != null && MobileParty.MainParty.Army.LeaderParty != MobileParty.MainParty;
		}

		// Token: 0x060028A9 RID: 10409 RVA: 0x000ADA84 File Offset: 0x000ABC84
		private void FinishBattle()
		{
			List<MobileParty> list = new List<MobileParty>();
			if (this.AttackersRanAway)
			{
				foreach (MapEventParty mapEventParty in this.AttackerSide.Parties)
				{
					if (mapEventParty.Party.IsMobile)
					{
						list.Add(mapEventParty.Party.MobileParty);
					}
				}
			}
			this._isFinishCalled = true;
			if (!this._battleResultsCalculated)
			{
				this.CalculateBattleResults(false);
			}
			this.ApplyBattleResults();
			this.FinalizeEventAux();
			if (this.AttackersRanAway)
			{
				foreach (MobileParty mobileParty in list)
				{
					if (mobileParty.IsActive && mobileParty.AttachedTo == null)
					{
						if (mobileParty.BesiegerCamp != null)
						{
							mobileParty.BesiegerCamp = null;
						}
						mobileParty.TeleportPartyToSafePosition(3.3f, 3f);
						mobileParty.Ai.SetMoveModeHold();
					}
				}
			}
		}

		// Token: 0x17000A3F RID: 2623
		// (get) Token: 0x060028AA RID: 10410 RVA: 0x000ADBA4 File Offset: 0x000ABDA4
		public MapEventResultExplainer BattleResultExplainers
		{
			get
			{
				return this._battleResultExplainers;
			}
		}

		// Token: 0x060028AB RID: 10411 RVA: 0x000ADBAC File Offset: 0x000ABDAC
		public override string ToString()
		{
			object[] array = new object[4];
			array[0] = "Battle: ";
			int num = 1;
			PartyBase leaderParty = this.AttackerSide.LeaderParty;
			array[num] = ((leaderParty != null) ? leaderParty.Name : null);
			array[2] = " x ";
			array[3] = this.DefenderSide.LeaderParty.Name;
			return string.Concat(array);
		}

		// Token: 0x060028AC RID: 10412 RVA: 0x000ADC04 File Offset: 0x000ABE04
		internal void CalculateBattleResults(bool forScoreBoard = false)
		{
			if (this._battleResultsCalculated)
			{
				return;
			}
			this._battleResultsCalculated = !forScoreBoard;
			LootCollector lootCollector = new LootCollector();
			if (this.IsPlayerMapEvent)
			{
				this._battleResultExplainers = new MapEventResultExplainer();
				if (PlayerEncounter.EncounteredPartySurrendered)
				{
					this._sides[(int)this.DefeatedSide.GetOppositeSide()].ResetContributionToBattleToStrength();
				}
			}
			if (this.BattleState == BattleState.AttackerVictory || this.BattleState == BattleState.DefenderVictory)
			{
				int num = this.CalculatePlunderedGold();
				if (!forScoreBoard)
				{
					this.LootDefeatedParties(out this.PlayerCaptured, lootCollector);
					this.CalculatePlunderedGoldShares((float)num, this._battleResultExplainers);
				}
				if (!forScoreBoard)
				{
					this.CalculateLootShares(lootCollector);
				}
				this.CalculateRenownShares(this._battleResultExplainers, forScoreBoard);
			}
		}

		// Token: 0x060028AD RID: 10413 RVA: 0x000ADCA9 File Offset: 0x000ABEA9
		private void CalculatePlunderedGoldShares(float totalPlunderedGold, MapEventResultExplainer resultExplainers = null)
		{
			if (this.BattleState == BattleState.AttackerVictory || this.BattleState == BattleState.DefenderVictory)
			{
				((this.BattleState == BattleState.AttackerVictory) ? this.AttackerSide : this.DefenderSide).CalculatePlunderedGoldShare(totalPlunderedGold, resultExplainers);
			}
		}

		// Token: 0x060028AE RID: 10414 RVA: 0x000ADCDB File Offset: 0x000ABEDB
		internal void ApplyBattleResults()
		{
			if (this._battleResultsCommitted)
			{
				return;
			}
			this.CommitXpGains();
			this.ApplyRenownAndInfluenceChanges();
			this.ApplyRewardsAndChanges();
			this._battleResultsCommitted = true;
		}

		// Token: 0x060028AF RID: 10415 RVA: 0x000ADD00 File Offset: 0x000ABF00
		private void ApplyRewardsAndChanges()
		{
			MapEventSide[] sides = this._sides;
			for (int i = 0; i < sides.Length; i++)
			{
				sides[i].ApplyFinalRewardsAndChanges();
			}
		}

		// Token: 0x060028B0 RID: 10416 RVA: 0x000ADD2C File Offset: 0x000ABF2C
		internal void ApplyRenownAndInfluenceChanges()
		{
			MapEventSide[] sides = this._sides;
			for (int i = 0; i < sides.Length; i++)
			{
				sides[i].ApplyRenownAndInfluenceChanges();
			}
		}

		// Token: 0x060028B1 RID: 10417 RVA: 0x000ADD58 File Offset: 0x000ABF58
		private void CommitXpGains()
		{
			MapEventSide[] sides = this._sides;
			for (int i = 0; i < sides.Length; i++)
			{
				sides[i].CommitXpGains();
			}
		}

		// Token: 0x060028B2 RID: 10418 RVA: 0x000ADD82 File Offset: 0x000ABF82
		internal void ResetBattleResults()
		{
			this._battleResultsCommitted = false;
		}

		// Token: 0x17000A40 RID: 2624
		// (get) Token: 0x060028B3 RID: 10419 RVA: 0x000ADD8B File Offset: 0x000ABF8B
		public bool IsFinalized
		{
			get
			{
				return this._state == MapEventState.WaitingRemoval;
			}
		}

		// Token: 0x060028B4 RID: 10420 RVA: 0x000ADD96 File Offset: 0x000ABF96
		public void FinalizeEvent()
		{
			this.FinalizeEventAux();
		}

		// Token: 0x060028B5 RID: 10421 RVA: 0x000ADDA0 File Offset: 0x000ABFA0
		private void FinalizeEventAux()
		{
			if (this.IsFinalized)
			{
				return;
			}
			this.State = MapEventState.WaitingRemoval;
			CampaignEventDispatcher.Instance.OnMapEventEnded(this);
			bool flag = false;
			if (this.MapEventSettlement != null)
			{
				if ((this.IsSiegeAssault || this.IsSiegeOutside || this.IsSallyOut) && this.MapEventSettlement.SiegeEvent != null)
				{
					this.MapEventSettlement.SiegeEvent.OnBeforeSiegeEventEnd(this.BattleState, this._mapEventType);
				}
				if (!this._keepSiegeEvent && (this.IsSiegeAssault || this.IsSiegeOutside))
				{
					BattleState battleState = this.BattleState;
					if (battleState != BattleState.DefenderVictory)
					{
						if (battleState == BattleState.AttackerVictory)
						{
							CampaignEventDispatcher.Instance.SiegeCompleted(this.MapEventSettlement, this.AttackerSide.LeaderParty.MobileParty, true, this._mapEventType);
							flag = true;
						}
					}
					else
					{
						SiegeEvent siegeEvent = this.MapEventSettlement.SiegeEvent;
						if (siegeEvent != null)
						{
							siegeEvent.BesiegerCamp.RemoveAllSiegeParties();
						}
						CampaignEventDispatcher.Instance.SiegeCompleted(this.MapEventSettlement, this.AttackerSide.LeaderParty.MobileParty, false, this._mapEventType);
					}
				}
				else if (this.IsSallyOut && this.MapEventSettlement.Town != null && this.MapEventSettlement.Town.GarrisonParty != null && this.MapEventSettlement.Town.GarrisonParty.IsActive)
				{
					this.MapEventSettlement.Town.GarrisonParty.Ai.SetMoveModeHold();
				}
				MapEventComponent component = this.Component;
				if (component != null)
				{
					component.FinalizeComponent();
				}
			}
			foreach (MapEventSide mapEventSide in this._sides)
			{
				mapEventSide.UpdatePartiesMoveState();
				mapEventSide.HandleMapEventEnd();
			}
			IMapEventVisual mapEventVisual = this.MapEventVisual;
			if (mapEventVisual != null)
			{
				mapEventVisual.OnMapEventEnd();
			}
			foreach (PartyBase partyBase in this.InvolvedParties)
			{
				if (partyBase.IsMobile)
				{
					partyBase.MobileParty.EventPositionAdder = Vec2.Zero;
				}
				partyBase.SetVisualAsDirty();
				if (partyBase.IsMobile && partyBase.MobileParty.Army != null && partyBase.MobileParty.Army.LeaderParty == partyBase.MobileParty)
				{
					foreach (MobileParty mobileParty in partyBase.MobileParty.Army.LeaderParty.AttachedParties)
					{
						mobileParty.Party.SetVisualAsDirty();
					}
				}
			}
			if (this._mapEventType != MapEvent.BattleTypes.Siege && this._mapEventType != MapEvent.BattleTypes.SiegeOutside && this._mapEventType != MapEvent.BattleTypes.SallyOut)
			{
				foreach (PartyBase partyBase2 in this.InvolvedParties)
				{
					if (partyBase2.IsMobile && partyBase2 != PartyBase.MainParty && partyBase2.MobileParty.BesiegedSettlement != null && (partyBase2.MobileParty.Army == null || partyBase2.MobileParty.Army.LeaderParty == partyBase2.MobileParty))
					{
						if (partyBase2.IsActive)
						{
							EncounterManager.StartSettlementEncounter(partyBase2.MobileParty, partyBase2.MobileParty.BesiegedSettlement);
						}
						else
						{
							partyBase2.MobileParty.BesiegerCamp = null;
						}
					}
				}
			}
			if (flag)
			{
				this.MapEventSettlement.Militia += (float)Campaign.Current.Models.SettlementMilitiaModel.MilitiaToSpawnAfterSiege(this.MapEventSettlement.Town);
			}
			MapEventSide[] sides = this._sides;
			for (int i = 0; i < sides.Length; i++)
			{
				sides[i].Clear();
			}
		}

		// Token: 0x17000A41 RID: 2625
		// (get) Token: 0x060028B6 RID: 10422 RVA: 0x000AE170 File Offset: 0x000AC370
		public CampaignTime BattleStartTime
		{
			get
			{
				return this._mapEventStartTime;
			}
		}

		// Token: 0x17000A42 RID: 2626
		// (get) Token: 0x060028B7 RID: 10423 RVA: 0x000AE178 File Offset: 0x000AC378
		public bool HasWinner
		{
			get
			{
				return this.BattleState == BattleState.AttackerVictory || this.BattleState == BattleState.DefenderVictory;
			}
		}

		// Token: 0x17000A43 RID: 2627
		// (get) Token: 0x060028B8 RID: 10424 RVA: 0x000AE18E File Offset: 0x000AC38E
		// (set) Token: 0x060028B9 RID: 10425 RVA: 0x000AE196 File Offset: 0x000AC396
		[SaveableProperty(123)]
		public bool IsPlayerSimulation { get; set; }

		// Token: 0x060028BA RID: 10426 RVA: 0x000AE1A0 File Offset: 0x000AC3A0
		public bool HasTroopsOnBothSides()
		{
			bool flag = this.PartiesOnSide(BattleSideEnum.Attacker).Any((MapEventParty party) => party.Party.NumberOfHealthyMembers > 0);
			bool flag2 = this.PartiesOnSide(BattleSideEnum.Defender).Any((MapEventParty party) => party.Party.NumberOfHealthyMembers > 0);
			return flag && flag2;
		}

		// Token: 0x060028BB RID: 10427 RVA: 0x000AE206 File Offset: 0x000AC406
		public PartyBase GetLeaderParty(BattleSideEnum side)
		{
			return this._sides[(int)side].LeaderParty;
		}

		// Token: 0x060028BC RID: 10428 RVA: 0x000AE215 File Offset: 0x000AC415
		public float GetRenownValue(BattleSideEnum side)
		{
			return this._sides[(int)side].RenownValue;
		}

		// Token: 0x060028BD RID: 10429 RVA: 0x000AE224 File Offset: 0x000AC424
		public float GetRenownValueAtMapEventEnd(BattleSideEnum side)
		{
			return this._sides[(int)side].RenownAtMapEventEnd;
		}

		// Token: 0x060028BE RID: 10430 RVA: 0x000AE234 File Offset: 0x000AC434
		public void RecalculateRenownAndInfluenceValues(PartyBase party)
		{
			this.StrengthOfSide[(int)party.Side] += party.TotalStrength;
			MapEventSide[] sides = this._sides;
			for (int i = 0; i < sides.Length; i++)
			{
				sides[i].CalculateRenownAndInfluenceValues(this.StrengthOfSide);
			}
		}

		// Token: 0x060028BF RID: 10431 RVA: 0x000AE280 File Offset: 0x000AC480
		public void RecalculateStrengthOfSides()
		{
			foreach (MapEventSide mapEventSide in this._sides)
			{
				this.StrengthOfSide[(int)mapEventSide.MissionSide] = mapEventSide.RecalculateStrengthOfSide();
			}
		}

		// Token: 0x060028C0 RID: 10432 RVA: 0x000AE2B9 File Offset: 0x000AC4B9
		public void DoSurrender(BattleSideEnum side)
		{
			this.GetMapEventSide(side).Surrender();
			this.BattleState = ((side == BattleSideEnum.Defender) ? BattleState.AttackerVictory : BattleState.DefenderVictory);
		}

		// Token: 0x060028C1 RID: 10433 RVA: 0x000AE2D4 File Offset: 0x000AC4D4
		internal BattleSideEnum GetOtherSide(BattleSideEnum side)
		{
			if (side != BattleSideEnum.Attacker)
			{
				return BattleSideEnum.Attacker;
			}
			return BattleSideEnum.Defender;
		}

		// Token: 0x060028C2 RID: 10434 RVA: 0x000AE2E0 File Offset: 0x000AC4E0
		private void ResetUnsuitablePartiesThatWereTargetingThisMapEvent()
		{
			LocatableSearchData<MobileParty> locatableSearchData = MobileParty.StartFindingLocatablesAroundPosition(this.Position, 15f);
			for (MobileParty mobileParty = MobileParty.FindNextLocatable(ref locatableSearchData); mobileParty != null; mobileParty = MobileParty.FindNextLocatable(ref locatableSearchData))
			{
				if (!mobileParty.IsMainParty && mobileParty.ShortTermBehavior == AiBehavior.EngageParty && (mobileParty.ShortTermTargetParty == this.GetLeaderParty(BattleSideEnum.Attacker).MobileParty || mobileParty.ShortTermTargetParty == this.GetLeaderParty(BattleSideEnum.Defender).MobileParty) && !this.CanPartyJoinBattle(mobileParty.Party, BattleSideEnum.Attacker) && !this.CanPartyJoinBattle(mobileParty.Party, BattleSideEnum.Defender))
				{
					mobileParty.Ai.SetMoveModeHold();
				}
			}
		}

		// Token: 0x060028C3 RID: 10435 RVA: 0x000AE375 File Offset: 0x000AC575
		private void CacheSimulationData()
		{
			this._sides[0].CacheLeaderSimulationModifier();
			this._sides[1].CacheLeaderSimulationModifier();
			this.SimulationContext = this.DetermineContext();
		}

		// Token: 0x060028C4 RID: 10436 RVA: 0x000AE3A0 File Offset: 0x000AC5A0
		private MapEvent.PowerCalculationContext DetermineContext()
		{
			MapEvent.PowerCalculationContext result = MapEvent.PowerCalculationContext.Default;
			MapWeatherModel.WeatherEvent weatherEventInPosition = Campaign.Current.Models.MapWeatherModel.GetWeatherEventInPosition(this.Position);
			if (weatherEventInPosition == MapWeatherModel.WeatherEvent.Snowy || weatherEventInPosition == MapWeatherModel.WeatherEvent.Blizzard)
			{
				result = MapEvent.PowerCalculationContext.SnowBattle;
			}
			switch (this.EventType)
			{
			case MapEvent.BattleTypes.FieldBattle:
			case MapEvent.BattleTypes.SallyOut:
			case MapEvent.BattleTypes.SiegeOutside:
				switch (this.EventTerrainType)
				{
				case TerrainType.Water:
				case TerrainType.Swamp:
				case TerrainType.Bridge:
				case TerrainType.River:
				case TerrainType.Fording:
				case TerrainType.Lake:
					result = MapEvent.PowerCalculationContext.RiverCrossingBattle;
					break;
				case TerrainType.Steppe:
					result = MapEvent.PowerCalculationContext.SteppeBattle;
					break;
				case TerrainType.Plain:
					result = MapEvent.PowerCalculationContext.PlainBattle;
					break;
				case TerrainType.Desert:
					result = MapEvent.PowerCalculationContext.DesertBattle;
					break;
				case TerrainType.Dune:
					result = MapEvent.PowerCalculationContext.DuneBattle;
					break;
				case TerrainType.Forest:
					result = MapEvent.PowerCalculationContext.ForestBattle;
					break;
				}
				break;
			case MapEvent.BattleTypes.Raid:
			case MapEvent.BattleTypes.IsForcingVolunteers:
			case MapEvent.BattleTypes.IsForcingSupplies:
				result = MapEvent.PowerCalculationContext.Village;
				break;
			case MapEvent.BattleTypes.Siege:
				result = MapEvent.PowerCalculationContext.Siege;
				break;
			}
			return result;
		}

		// Token: 0x17000A44 RID: 2628
		// (get) Token: 0x060028C5 RID: 10437 RVA: 0x000AE468 File Offset: 0x000AC668
		Vec2 IMapEntity.InteractionPosition
		{
			get
			{
				return this.Position;
			}
		}

		// Token: 0x17000A45 RID: 2629
		// (get) Token: 0x060028C6 RID: 10438 RVA: 0x000AE470 File Offset: 0x000AC670
		TextObject IMapEntity.Name
		{
			get
			{
				return this.GetName();
			}
		}

		// Token: 0x17000A46 RID: 2630
		// (get) Token: 0x060028C7 RID: 10439 RVA: 0x000AE478 File Offset: 0x000AC678
		bool IMapEntity.IsMobileEntity
		{
			get
			{
				return false;
			}
		}

		// Token: 0x17000A47 RID: 2631
		// (get) Token: 0x060028C8 RID: 10440 RVA: 0x000AE47B File Offset: 0x000AC67B
		bool IMapEntity.ShowCircleAroundEntity
		{
			get
			{
				return false;
			}
		}

		// Token: 0x060028C9 RID: 10441 RVA: 0x000AE47E File Offset: 0x000AC67E
		bool IMapEntity.OnMapClick(bool followModifierUsed)
		{
			return false;
		}

		// Token: 0x060028CA RID: 10442 RVA: 0x000AE481 File Offset: 0x000AC681
		void IMapEntity.OnOpenEncyclopedia()
		{
		}

		// Token: 0x060028CB RID: 10443 RVA: 0x000AE483 File Offset: 0x000AC683
		void IMapEntity.OnHover()
		{
			InformationManager.ShowTooltip(typeof(MapEvent), new object[]
			{
				this
			});
		}

		// Token: 0x060028CC RID: 10444 RVA: 0x000AE49E File Offset: 0x000AC69E
		bool IMapEntity.IsEnemyOf(IFaction faction)
		{
			return false;
		}

		// Token: 0x060028CD RID: 10445 RVA: 0x000AE4A1 File Offset: 0x000AC6A1
		bool IMapEntity.IsAllyOf(IFaction faction)
		{
			return false;
		}

		// Token: 0x060028CE RID: 10446 RVA: 0x000AE4A4 File Offset: 0x000AC6A4
		public void GetMountAndHarnessVisualIdsForPartyIcon(out string mountStringId, out string harnessStringId)
		{
			mountStringId = "";
			harnessStringId = "";
		}

		// Token: 0x060028CF RID: 10447 RVA: 0x000AE4B4 File Offset: 0x000AC6B4
		void IMapEntity.OnPartyInteraction(MobileParty mobileParty)
		{
		}

		// Token: 0x060028D0 RID: 10448 RVA: 0x000AE4B8 File Offset: 0x000AC6B8
		public bool CanPartyJoinBattle(PartyBase party, BattleSideEnum side)
		{
			return this.GetMapEventSide(side).Parties.All((MapEventParty x) => !x.Party.MapFaction.IsAtWarWith(party.MapFaction)) && this.GetMapEventSide(this.GetOtherSide(side)).Parties.All((MapEventParty x) => x.Party.MapFaction.IsAtWarWith(party.MapFaction));
		}

		// Token: 0x060028D1 RID: 10449 RVA: 0x000AE518 File Offset: 0x000AC718
		public void GetStrengthsRelativeToParty(BattleSideEnum partySide, out float partySideStrength, out float opposingSideStrength)
		{
			partySideStrength = 0.1f;
			opposingSideStrength = 0.1f;
			if (this != null)
			{
				using (IEnumerator<PartyBase> enumerator = this.InvolvedParties.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						PartyBase partyBase = enumerator.Current;
						if (partyBase.Side == partySide)
						{
							partySideStrength += partyBase.TotalStrength;
						}
						else
						{
							opposingSideStrength += partyBase.TotalStrength;
						}
					}
					return;
				}
			}
			Debug.FailedAssert("Cannot retrieve party strengths. MapEvent parameter is null.", "C:\\Develop\\MB3\\Source\\Bannerlord\\TaleWorlds.CampaignSystem\\MapEvents\\MapEvent.cs", "GetStrengthsRelativeToParty", 1940);
		}

		// Token: 0x060028D2 RID: 10450 RVA: 0x000AE5AC File Offset: 0x000AC7AC
		public bool CheckIfBattleShouldContinueAfterBattleMission(CampaignBattleResult campaignBattleResult)
		{
			if (PlayerEncounter.PlayerSurrender || campaignBattleResult == null || campaignBattleResult.EnemyRetreated)
			{
				return false;
			}
			bool flag = this.IsSiegeAssault && this.BattleState == BattleState.AttackerVictory;
			MapEventSide mapEventSide = this.GetMapEventSide(this.PlayerSide);
			bool flag2 = (campaignBattleResult.PlayerDefeat && mapEventSide.GetTotalHealthyTroopCountOfSide() >= 1) || ((campaignBattleResult.PlayerVictory || campaignBattleResult.EnemyPulledBack) && this.DefeatedSide != BattleSideEnum.None && this.GetMapEventSide(this.DefeatedSide).GetTotalHealthyTroopCountOfSide() >= 1);
			return !this.IsHideoutBattle && !flag && flag2 && !mapEventSide.IsSurrendered;
		}

		// Token: 0x04000C3F RID: 3135
		private const float BattleRetreatMinimumTime = 1f;

		// Token: 0x04000C40 RID: 3136
		private const float SiegeDefenderAdvantage = 2f;

		// Token: 0x04000C41 RID: 3137
		private const int MapEventSettlementSettingDistance = 3;

		// Token: 0x04000C44 RID: 3140
		[SaveableField(101)]
		private MapEventState _state;

		// Token: 0x04000C45 RID: 3141
		[SaveableField(102)]
		private MapEventSide[] _sides = new MapEventSide[2];

		// Token: 0x04000C47 RID: 3143
		public const float SiegeAdvantage = 1.5f;

		// Token: 0x04000C48 RID: 3144
		public bool DiplomaticallyFinished;

		// Token: 0x04000C4A RID: 3146
		[SaveableField(106)]
		private int _mapEventUpdateCount;

		// Token: 0x04000C4B RID: 3147
		[CachedData]
		internal MapEvent.PowerCalculationContext SimulationContext;

		// Token: 0x04000C4C RID: 3148
		[SaveableField(107)]
		private CampaignTime _nextSimulationTime;

		// Token: 0x04000C4D RID: 3149
		[SaveableField(108)]
		private CampaignTime _mapEventStartTime;

		// Token: 0x04000C4E RID: 3150
		[SaveableField(110)]
		private MapEvent.BattleTypes _mapEventType;

		// Token: 0x04000C50 RID: 3152
		[CachedData]
		private TerrainType _eventTerrainType;

		// Token: 0x04000C52 RID: 3154
		[CachedData]
		public IMapEventVisual MapEventVisual;

		// Token: 0x04000C53 RID: 3155
		[SaveableField(114)]
		private bool _isVisible;

		// Token: 0x04000C54 RID: 3156
		private bool _keepSiegeEvent;

		// Token: 0x04000C55 RID: 3157
		[SaveableField(116)]
		private bool FirstUpdateIsDone;

		// Token: 0x04000C56 RID: 3158
		[SaveableField(117)]
		private BattleState _battleState;

		// Token: 0x04000C57 RID: 3159
		private bool _isFinishCalled;

		// Token: 0x04000C58 RID: 3160
		private bool _battleResultsCalculated;

		// Token: 0x04000C59 RID: 3161
		private bool _battleResultsCommitted;

		// Token: 0x04000C5A RID: 3162
		private bool PlayerCaptured;

		// Token: 0x04000C5B RID: 3163
		private MapEventResultExplainer _battleResultExplainers;

		// Token: 0x04000C5D RID: 3165
		[SaveableField(125)]
		public float[] StrengthOfSide = new float[2];

		// Token: 0x020005DD RID: 1501
		public enum BattleTypes
		{
			// Token: 0x04001829 RID: 6185
			None,
			// Token: 0x0400182A RID: 6186
			FieldBattle,
			// Token: 0x0400182B RID: 6187
			Raid,
			// Token: 0x0400182C RID: 6188
			IsForcingVolunteers,
			// Token: 0x0400182D RID: 6189
			IsForcingSupplies,
			// Token: 0x0400182E RID: 6190
			Siege,
			// Token: 0x0400182F RID: 6191
			Hideout,
			// Token: 0x04001830 RID: 6192
			SallyOut,
			// Token: 0x04001831 RID: 6193
			SiegeOutside
		}

		// Token: 0x020005DE RID: 1502
		public enum PowerCalculationContext
		{
			// Token: 0x04001833 RID: 6195
			Default,
			// Token: 0x04001834 RID: 6196
			PlainBattle,
			// Token: 0x04001835 RID: 6197
			SteppeBattle,
			// Token: 0x04001836 RID: 6198
			DesertBattle,
			// Token: 0x04001837 RID: 6199
			DuneBattle,
			// Token: 0x04001838 RID: 6200
			SnowBattle,
			// Token: 0x04001839 RID: 6201
			ForestBattle,
			// Token: 0x0400183A RID: 6202
			RiverCrossingBattle,
			// Token: 0x0400183B RID: 6203
			Village,
			// Token: 0x0400183C RID: 6204
			Siege
		}
	}
}
